<?php
if (isset($_SESSION['admin-login'])) {
	if (isset($_POST['post'])) {
		$nama = amankan($_POST['nama']);
		$harga = intval($_POST['harga']);
		$deskripsi = amankan($_POST['deskripsi']);
		$kategori = amankan($_POST['kategori']);
		if ($_FILES['image']['error'] == 0) {
			$tgl = date("Y-m-d H:i:s");
			$kategori = kategoring($kategori);
			$id = db_insert("INSERT INTO produk (nama,harga,deskripsi,kategori,tgl,dipesan) VALUES ('$nama',$harga,'$deskripsi','$kategori','$tgl',0)");
			$slug = slugging($_POST['nama'],"produk",$id);
			db_query("UPDATE produk SET slug = '$slug' WHERE id = $id");
			rapikan_kategori();
			move_uploaded_file($_FILES['image']['tmp_name'],asset_path()."/images/produk/".$id.".jpg");
			$_SESSION['status-produk'] = "Produk sudah dimasukkan";
			header("Location: ".site()."/".$param[0]."/produk");
		} else {
			$_SESSION['status-produk-new'] = "Upload gagal. Error Code : ".$_FILES['image']['error'];
			header("Location: ".site()."/".$param[0]."/produk-new");
		}
	}
} else {
	$_SESSION['status-login'] = "Log in terlebih dahulu untuk melanjutkan";
	header("Location: ".site()."/".$param[0]."/login");
}
?>